package com.cn.txx.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cn.txx.entity.DCity;
import com.cn.txx.entity.User;
import com.cn.txx.entity.UserCity;
import com.cn.txx.service.WelcomeService;
import com.cn.txx.utils.Constants;

@RequestMapping("/welcome")
@Controller
public class WelcomeController {

	@Autowired
	private WelcomeService welcomservice;
	
	@RequestMapping("/loadCityByPro.do")
	@ResponseBody
	public List<DCity> loadCityByPro(){
		return welcomservice.loadCityByPro();
	}
	
	@RequestMapping("/loadCityByUser.do")
	@ResponseBody
	public List<UserCity> loadCityByUser(HttpServletRequest request){
		User user = (User) request.getSession().getAttribute(Constants.CURRENT_USER);
		if(user == null){
			return null;
		}
		return welcomservice.loadCityByUser(user.getT_UID());
	}
}
